package com.vpclub.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**集中处理所有异常
 *
 *
 *      1.集中处理所有异常的类加入到IOC容器中
 *      2.@ControllerAdvice专门处理异常的类
 *
 *
 * @author : leimingchao
 * @date Date : 2021年08月02日 23:55
 */
@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(value = {ArithmeticException.class})
    public ModelAndView handleException01(Exception exception) {
        System.out.println("全局的handleException01...." + exception);
        ModelAndView mv = new ModelAndView("myerror");
        mv.addObject("ex",exception);
        //视图解析器拼串
        return mv;
    }

    // @ExceptionHandler(value = {Exception.class})
    // public ModelAndView handleException02(Exception exception) {
    //     System.out.println("全局的handleException02...." + exception);
    //     ModelAndView mv = new ModelAndView("myerror");
    //     mv.addObject("ex",exception);
    //     //视图解析器拼串
    //     return mv;
    // }
}
